/*---------------------------------------------------------------------------
	ZaRan	-	A Totallly Automatic CFD Software
	Copyright (C) ,Since 2020
-------------------------------------------------------------------------------
License
	This file is part of ZaRan.

!	@file		gird.h
!	@brief	the purpose of this file.
!	@author	Chen Jie.
\*---------------------------------------------------------------------------*/
#include"TestCase/include/TestCase.h"
#include"numerics/convection/include/InviscidSolver.h"
#include"flux/include/flux.h"
#include"Basic/include/CommonPara.h"
#include"numerics/convection/include/vanleer.h"
#include<ctime>
#include<iostream>

void TestPointCloudReadSpeed()
{
	clock_t start, end;
	int pointNum = 77063;
	int testPointNum = 90000;
	vector<Point>pointVec;
	vector<Point>testPoint;
	pointVec.resize(pointNum);
	for (size_t iPoint = 0; iPoint < pointNum; iPoint++)
	{
		double x = rand() / double(RAND_MAX) * 100;
		double y = rand() / double(RAND_MAX) * 100;
		double z = rand() / double(RAND_MAX) * 100;
		pointVec[iPoint] = { x,y,z };
	}
	testPoint.resize(testPointNum);
	for (size_t iPoint = 0; iPoint < testPointNum; ++iPoint)
	{
		double x = rand() / double(RAND_MAX) * 100;
		double y = rand() / double(RAND_MAX) * 100;
		double z = rand() / double(RAND_MAX) * 100;
		testPoint[iPoint] = { x,y,z };
	}
	ModPointCloud model(pointVec);
	std::cout << "*******************************" << std::endl;
	std::cout << "KD-Tree Search" << std::endl;
	std::cout << "Start Search!" << std::endl;
	start = clock();
	for (size_t iPoint = 0; iPoint < testPointNum; iPoint++)
	{
		model.GetClosestPoint(testPoint[iPoint]);
	}
	end = clock();
	std::cout << "End Search!" << std::endl;
	std::cout << "Cost Time:" << (end - start) / double(CLOCKS_PER_SEC) << "s" << std::endl;
	std::cout << "*******************************" << std::endl;
	std::cout << std::endl;
	std::cout << "###############################" << std::endl;
	std::cout << "Original Search" << std::endl;
	std::cout << "Start Search!" << std::endl;
	start = clock();
	int id;
	for (size_t iPoint = 0; iPoint < testPointNum; ++iPoint)
	{
		double mindis = DBL_MAX;
		double dis;

		for (size_t jPoint = 0; jPoint < pointNum; ++jPoint)
		{
			dis = distance(pointVec[jPoint], testPoint[iPoint]);
			mindis = std::min(mindis, dis);
			if (abs(mindis - dis) < SMALL_NUMBER)
				id = jPoint;
		}
	}
	end = clock();
	std::cout << "End Search!" << std::endl;
	std::cout << "Cost Time:" << (end - start) / double(CLOCKS_PER_SEC) << "s" << std::endl;
	std::cout << "###############################" << std::endl;

}
//void TestMatPlotLib()
//{
//	namespace plt = matplotlibcpp;
//	// Prepare data.
//	int n = 5000;
//	std::vector<double> x(n), y(n), z(n), w(n, 2);
//	for (int i = 0; i < n; ++i) {
//		x.at(i) = i * i;
//		y.at(i) = sin(2 * 3.14159265358979323846 * i / 360.0);
//		z.at(i) = log(i);
//	}
//
//	// Set the size of output image = 1200x780 pixels
//	plt::figure_size(1200, 780);
//
//	// Plot line from given x and y data. Color is selected automatically.
//	plt::plot(x, y);
//
//	// Plot a red dashed line from given x and y data.
//	plt::plot(x, w, "r--");
//
//	// Plot a line whose name will show up as "log(x)" in the legend.
//	plt::named_plot("log(x)", x, z);
//
//	// Set x-axis to interval [0,1000000]
//	plt::xlim(0, 1000 * 1000);
//
//	// Add graph title
//	plt::title("Sample figure");
//
//	// Enable legend.
//	plt::legend();
//
//	// save figure
//	const char* filename = "./basic.png";
//	std::cout << "Saving result to " << filename << std::endl;;
//	plt::save(filename);
//}
void TestRiemannSolver()
{
	//InviscidSolver* riemann = new VanLeer;
	//vector<VarList>neibor_var(4);
	//neibor_var[0] = VarList(vector<double>{1.401698470116, 0.009371549822, -0.167363449931, 0, 1.007374882698});
	//neibor_var[1] = VarList(vector<double>{1.401749968529, 2.994471311569, 0.000002310363, 0, 1.007599711418});
	//neibor_var[2] = VarList(vector<double>{1.399999976158, 3, 0, 0, 1});
	//neibor_var[3] = VarList(vector<double>{1.40152452316, 2.995074033737, -0.000355830678, 0, 1.006781578064});
	//vector<Point>neibor_point(4);
	//neibor_point[0] = Point(-0.01997776702, -0.0009427599);
	//neibor_point[1] = Point(-0.021, -0.0);
	//neibor_point[2] = Point(-0.022, -0.001);
	//neibor_point[3] = Point(-0.021, -0.002);
	//VarList local_var;

	//local_var = VarList(vector<double>{1.401698470116, 3, 0, 0, 1});
	//CoordTrans local_coord_trans(2, neibor_point);

	//VarList flux = riemann->UpdateFlux(local_var, neibor_var, local_coord_trans);
	//return;
}